package com.jstyle.jclife.adapter;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.jstyle.jclife.R;
import com.jstyle.jclife.model.TeamInfoDetail;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhuge on 2017/2/25 0025.
 */

public class TeamAdapter extends RecyclerView.Adapter {
    List<TeamInfoDetail> sleepDetails;
    public TeamAdapter() {
        this.sleepDetails = new ArrayList<>();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_team, parent, false));

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        final TeamInfoDetail sleepDetail = sleepDetails.get(position);
        final ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.teamname.setText(sleepDetail.getTeamname());
        viewHolder.injion.setText(sleepDetail.isIsinjonin()?"已加入":"加入");
    }





    public void setData(List<TeamInfoDetail> sleepDetails) {
        this.sleepDetails = sleepDetails;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return sleepDetails.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.teamname)
        TextView teamname;
        @BindView(R.id.injion)
        Button injion;
        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
